window.onload=function() {
    $('#Ds1_a').click(function () {
        $('#Ds1_a').css('color','rgb(177, 187, 126)');
        $('#Ds2_a').css('color','rgb(205, 223, 233)');
        $('#Ds3_a').css('color','rgb(205, 223, 233)');
    });
    $('#Ds2_a').click(function () {
        $('#Ds2_a').css('color','rgb(177, 187, 126)');
        $('#Ds1_a').css('color','rgb(205, 223, 233)');
        $('#Ds3_a').css('color','rgb(205, 223, 233)');
    });
    $('#Ds3_a').click(function () {
        $('#Ds3_a').css('color','rgb(177, 187, 126)');
        $('#Ds1_a').css('color','rgb(205, 223, 233)');
        $('#Ds2_a').css('color','rgb(205, 223, 233)');
    });

    // 查询div的显示和关闭
    $('#Sjcx').click(function (){
        $('#DSjcx').show();
    })
    $('#CloseDiv').click(function (){
        $('#DSjcx').hide();
    })
    $('#CloseDetailedDiv').click(function (){
        $('#DetailedInformation').hide();
    })

    // $('#Ds1').click(function (){
    //     $('#DetailedInformation').hide();
    //     $('#List').hide();
    //     CloseEntities();
    // })
    //
    // $('#Ds2').click(function (){
    //     $('#List').hide();
    //     $('#List_equ').show();
    //     $('#DetailedInformation').show();
    //     CloseEntities();
    // })
    // $('#Ds3').click(function (){
    //     $('#List').show();
    //     $('#DetailedInformation').show();
    //     $('#List_equ').hide();
    // })


    //数据展示功能：三维数据展示的切换
    //$('#3D_data2').hide();  //默认先把数据框2隐藏
    $('#qingxie').click(function (){
        $('#a_click2').css('color','rgb(177, 187, 126)');
        $('#a_click1').css('color','rgb(205, 223, 233)');
        $('#3D_data2').show();
        $('#3D_data1').hide();
    })

    $('#dianyun').click(function (){
        $('#a_click1').css('color','rgb(177, 187, 126)');
        $('#a_click2').css('color','rgb(205, 223, 233)');
        $('#3D_data1').show();
        $('#3D_data2').hide();
    })





}

function delete1(){
    console.log("a")
    var aa=$("#input_1").val()
    console.log($("#input_1").val())
}

var data1="[{\"id\":\"10000\",\"name\":\"惠和楼\",\"address\":\"中国**省**市**县\",\"lat\":\"45.9459819\",\"lon\":\"119.1145691\",\"pri\":\"15000\",\"url\":\"images/位置.png\",\"type\":\"建筑\"}," +
           "{\"id\":\"20000\",\"name\":\"住宿楼\",\"address\":\"中国**省**市**县\",\"lat\":\"45.9632302\",\"lon\":\"119.1347583\",\"pri\":\"13000\",\"url\":\"images/位置.png\",\"type\":\"建筑\"}," +
           "{\"id\":\"30000\",\"name\":\"穿孔机\",\"address\":\"中国**省**市**县\",\"lat\":\"45.93999661382169\",\"lon\":\"119.13901767908514\",\"pri\":\"13000\",\"url\":\"images/穿孔机.png\",\"type\":\"设备\"}," +
           "{\"id\":\"40000\",\"name\":\"脱水机械\",\"address\":\"中国**省**市**县\",\"lat\":\"45.92719269223041\",\"lon\":\"119.12912342419037\",\"pri\":\"13000\",\"url\":\"images/脱水机械.png\",\"type\":\"设备\"}]"
var datajson;
var idstr=[];
//根据搜索内容获取参数
function search_Data(){
    $('#close_search_div_btn').show(2);
    $(".input").animate({
        width:'70%',
    });
    var json = eval(data1);
   var json_data=[];
   var input_value= $('#input_1').val();
    //管线数据
        json.forEach((item, index) => {
            if (item.name.search(input_value) != -1 || item.type.search(input_value) != -1) {
               // console.log(item)
                json_data.push(item);
            }
        })
    search(json_data)

}

//html搜索内容展示
function search(json){
    CloseEntities1();
    $('#List').show();
    $('#Sxcx_search_div').show();
    $('#Sxcx_ul').hide();
    //var json = eval(data1);
    //datajson=json;
    htmlstr = "";
    htmlstr2 = "";
    document.getElementById('DetailedInformation_text').style.display='none';
    var i=0;
    $.each(json, function (index, value) {
        var id = json[index].id;
        var name = json[index].name;
        var address = json[index].address;
        var lat = json[index].lat;
        var lon = json[index].lon;
        var pri = json[index].pri;
        var url = json[index].url;
        var type = json[index].type;
        console.log(name,address,lat,lon,pri)

        htmlstr += '<div class="Datadiv" onclick="showpopup(this)" index="' + index + '">';
        htmlstr += '<div class="Datadiv1">' + name + '</div>';
        htmlstr += '<div class="Datadiv1">' + "地址：" + address + '</div>';
        htmlstr += '<div class="Datadiv1 Datadiv_Hide" >' + "维度：" + lat+";经度："+lon + '</div>';
        htmlstr += '<div class="Datadiv1">' + "参数1：" + pri + '</div>';
        htmlstr += '<div class="Datadiv1 Datadiv_Hide">' + id + '</div>';
        htmlstr += '</div>';
        $("#List").html(htmlstr);
        idstr[i]=id;
        console.log(idstr)
        i++;
        AddIcon(lat,lon,id,url);
    });

    viewer.camera.flyTo({
        destination: Cesium.Cartesian3.fromDegrees(119.1232357,45.9345041, 10000),
        orientation: {
            heading:Cesium.Math.toRadians(0),
            pitch:Cesium.Math.toRadians(-80),
            roll:0,
            //range:500
        }
    });

}

function AddDetailData(e){
    htmlstr1='';
    $('#DetailedInformation').show();
    var id = $(e.getElementsByTagName('div')[4]).text();
    var position = $(e.getElementsByTagName('div')[2]).text().split(/[：;]/);
    htmlstr1 += '<div class="Datadiv2">' + "id="+id+'</div>';
    htmlstr1 += '<div class="Datadiv2">' + position[0] +':'+position[1]+'</div>';
    htmlstr1 += '<div class="Datadiv2">' + position[2] +':'+position[3]+'</div>';
    htmlstr1 += '</div>';
    $("#DetailedInformation_text").html(htmlstr1);
}

function close_search_div(){
    $('#close_search_div_btn').hide();
    $('#Sxcx_search_div').hide();
    $('#Sxcx_ul').show();
    CloseEntities1();
    $(".input").animate({
        width:'84%',
    });
}



var temp=0;
$(document).ready(function(){
    var ClicdId=[];
    var i=0;
    // console.log("a")
    $(".left_guidance_Div").click(function(e){
        var div_value=$('#ChaXun_left_guidance').attr("value");
        ClicdId[temp] = $(e.target).attr('id');
        // console.log(ClicdId);
        if(temp!=0){
            temp=0;
        }else{
            temp=1;
        }
        if(i==0){
            $(".ChaXun_left_all").animate({
                left:'46px',
                width:'390px',
            });
            i=1;
        }
        else{
            if(ClicdId[0]===ClicdId[1]){
                // console.log("同一个");
                $(".ChaXun_left_all").animate({
                    width:'0px',
                    left:'0px',
                });
                huanyuan_2();
                i=0;
            }
            else{
                // console.log("不是同一个");
                $(".ChaXun_left_all").animate({
                    left:'46px',
                    width:'390px',
                });

            }
        }
    });
});

function huanyuan_2(){
    $("#Sxcx").hide();
    $("#Kjcx").hide();
    $("#Jkjc").hide();
    $(".top_right_table").hide();//详情页
    $('#ChaXun_left_guidance_Div_1').css('color','rgb(205, 223, 233)');
    $('#ChaXun_left_guidance_Div_2').css('color','rgb(205, 223, 233)');
    $('#jiance_left_guidance_Div_1').css('color','rgb(205, 223, 233)');
    $('#jiance_left_guidance_Div_2').css('color','rgb(205, 223, 233)');
}

var a=[0,0];
//1
$(document).ready(function(){
    // var a=0;
    $('#ChaXun_left_guidance_Div_1').click(function (){
        if (adata==0){
            $("#dataselecr_id").show();
            adata=1
        }else {
            $("#dataselecr_id").hide();
            adata=0
        }

        $("#catname").text('不动产信息')
        $("#mytable_list").hide();
        $('#kqdata').val('')
        $('#qydata').val('')

        if(a[0]===0){
            $("#Sxcx").show();
            //$(".top_right_table").show();
            $("#Kjcx").hide();

            $('#ChaXun_left_guidance_Div_2').css('color','rgb(205, 223, 233)');
            $('#ChaXun_left_guidance_Div_1').css('color','rgb(177, 187, 126)');
            a[0]=1;
            a[1]=0;

        }else{
            // console.log("a");
            a[0]=0;
        }
    });
});

//2
$(document).ready(function(){
    // var a=0;
    $('#ChaXun_left_guidance_Div_2').click(function (){
        $("#dataselecr_id").hide();
        adata=0
        if(a[1]===0){
            $("#Kjcx").show();
            $("#Sxcx").hide();
            $('#ChaXun_left_guidance_Div_1').css('color','rgb(205, 223, 233)');
            $('#ChaXun_left_guidance_Div_2').css('color','rgb(177, 187, 126)');
            a[0]=0;
            a[1]=1;
        }else{
            console.log("a");
            a[1]=0;
        }
    });
});
function addContentToDiv(divId, type, name, plate, time, buttonName,buttonName2) {
    console.log('创建')
    // clearDivContent(divId)
    // 引入layui的layer模块
    var layer = layui.layer;
    // 构造弹窗内容HTML代码
    var contentHtml=''
    if ($('#typeDateSelect').val()==='1'){
        contentHtml = '<div id="DetailedInformation_text_psCar" style="display: block;font-size:18px;text-align: left;background-color="rgb(13, 38, 68)";color: white;">' +
            '<p>定位类型：'+type+'</p>' +
            '<p>所属部门：'+name+'</p>' +
            '<p>编号信息：'+plate+'</p>' +
            '<p>定位时间：'+time+'</p>' +
            // '<button class="layui-btn layui-btn-normal viewLine">查看轨迹</button>'+
            // '<div className="layui-col-xs6">'+
            // '<button class="layui-btn layui-btn-normal viewCamera">查看摄像头</button>'+
            // '</div>'+
            '</div>';
    }else{
        contentHtml = '<div id="DetailedInformation_text_psCar" style="display: block;font-size:18px;text-align: left;background-color="rgb(13, 38, 68)";color: white;">' +
            '<p>定位类型：'+type+'</p>' +
            '<p>所属部门：'+name+'</p>' +
            '<p>编号信息：'+plate+'</p>' +
            '<p>定位时间：'+time+'</p>' +
        '<button class="layui-btn layui-btn-normal viewCamera">查看摄像头</button></div>';
    }

    // 弹出对话框，设置标题和内容
    layer.open({
        // type:2,
        title: '详细信息',
        content: contentHtml,
        // 显示关闭按钮
        size:"auto",
        // closeBtn: 1,
        // btnAlign: 'c',
        // 不显示任何按钮
        btn: [],
        // 不显示遮罩层
        shade: 0,
        position: 'fixed',
        offset: ['344px', '436.5px'],
        // area: ['200px','200px'],
        // shadeClose: true,
        // 弹窗打开后执行的回调函数，用于绑定查看摄像头按钮的点击事件
        success: function(layero, index) {
            // 获取弹窗中的查看摄像头按钮元素
            var btnc = $(layero).find('button.viewCamera');
            var btnl = $(layero).find('button.viewLine');
            // 绑定点击事件函数
            btnc.click(function() {
                // 在控制台输出一句话
                console.log('点击了查看摄像头按钮！');
                if (type==="人员定位"){
                    $("#vidoplay").show();
                    let video = document.getElementById('vidoplayid');
                    if (Hls.isSupported()) {
                        // video.display='block';
                        var hls = new Hls();
                        hls.loadSource('https://hls01open.ys7.com/openlive/84fd148491834c80be8c904abbd40a1b.m3u8');
                        hls.attachMedia(video);
                        hls.on(Hls.Events.MANIFEST_PARSED, function () {
                        });
                    }
                    video.play();
                }else{
                    $("#vidoplay").show();
                    let video = document.getElementById('vidoplayid');
                    if (Hls.isSupported()) {
                        // video.display='block';
                        var hls = new Hls();
                        hls.loadSource('https://hls01open.ys7.com/openlive/84fd148491834c80be8c904abbd40a1b.m3u8');
                        hls.attachMedia(video);
                        hls.on(Hls.Events.MANIFEST_PARSED, function () {
                        });
                    }
                    video.play();
                }
                // 关闭弹窗
                layer.close(index);
            });
            btnl.click(function() {
                // 在控制台输出一句话
                // console.log('点击了查看轨迹按钮！');
                // console.log(btnl.text)
                    // if (btnl.text==='查看轨迹'){
                    //     console.log(btnl)
                    //     addlinePlay(type,plate)
                        // btnl.text='关闭轨迹'
                    // }else{
                    //     console.log('关闭')
                    //     btnl.text='查看轨迹'
                    //     removeXjLine()
                    // }
                // 关闭弹窗
                // layer.close(index);
            });
        }
        ,cancel: function(){
            //右上角关闭回调
            removeXjLine()
            //return false 开启该代码可禁止点击该按钮关闭
        }
        ,end: function(){
            removeXjLine()
        }
    });

}
var primi_line;
function dateStringToTimestamp(dateString) {
    // 提取年、月、日、小时、分钟、秒
    const year = parseInt(dateString.substring(0, 4), 10);
    const month = parseInt(dateString.substring(4, 6), 10) - 1; // 月份从0开始，所以需要减1
    const day = parseInt(dateString.substring(6, 8), 10);
    const hours = parseInt(dateString.substring(8, 10), 10);
    const minutes = parseInt(dateString.substring(10, 12), 10);
    const seconds = parseInt(dateString.substring(12, 14), 10);

    // 使用Date对象构建日期
    const date = new Date(year, month, day, hours, minutes, seconds);

    // 返回时间戳
    return date.getTime();
}
function addlinePlay(text,txtName,tableData){
    removeXjLine()
    // const div = document.getElementById('DetailedInformation_text_psCar');
    // const firstParagraph = div.querySelector('p:first-of-type');
    // // const text = firstParagraph.textContent;
    // // var text
    let imageUrl=''
    // var thirdPTag = div.getElementsByTagName('p')[2];
    // var txtName = thirdPTag.textContent.split('：')[1];
    console.log(txtName)
    if (text.includes('人员')){
        imageUrl="./images/巡检定位人员.png"
    }
    if(text.includes('车辆')){
        imageUrl="./images/巡检定位车辆.png"
    }
    console.log(text); // 输出：这是第一个p标签。
//加轨迹线
//     let lineData = [106,39,132,48,120,32];
   let  list=     [{longitude: 119.10183200674953, latitude: 45.93223458324928, z: 960,yyyymmddhhmmss:1656047671018},
       {longitude: 119.10590618431968, latitude: 45.93431190644838, z: 960,  yyyymmddhhmmss:1656047771018},
       {longitude: 119.10909144133215, latitude: 45.93559199794587, z: 960,  yyyymmddhhmmss:1656047871018},
       {longitude: 119.11109432347152, latitude: 45.936454455184744, z: 960, yyyymmddhhmmss:1656047971018},
       {longitude: 119.112737926704, latitude: 45.93754714467318, z: 960,    yyyymmddhhmmss:1656048071018},
       {longitude: 119.11526275630773, latitude: 45.93698357474223, z: 960,  yyyymmddhhmmss:1656048171018},
       {longitude: 119.11825147035951, latitude: 45.93610950202259, z: 960,  yyyymmddhhmmss:1656048271018},
       {longitude: 119.1210426796725, latitude: 45.93741154288204, z: 960,   yyyymmddhhmmss:1656048371018},
       {longitude: 119.12238028665982, latitude: 45.93926272866539, z: 960,  yyyymmddhhmmss:1656048471018},
       {longitude: 119.12504975309261, latitude: 45.942558251467226, z:960,  yyyymmddhhmmss:1656048571018},
       {longitude: 119.1276581463349, latitude: 45.94567562149108, z: 960,   yyyymmddhhmmss:1656048671018},
       {longitude: 119.13021722967568, latitude: 45.94860918050941, z: 960,  yyyymmddhhmmss:1656048771018},
       {longitude: 119.13157722295736, latitude: 45.95019287583949, z: 960,  yyyymmddhhmmss:1656048871018},
       {longitude: 119.1330185554887, latitude: 45.95234781019482, z: 960,   yyyymmddhhmmss:1656048971018},
       {longitude: 119.13560532111717, latitude: 45.95730457546322, z: 960,  yyyymmddhhmmss:1656049071018},
       {longitude: 119.13328561967414, latitude: 45.96180236461524, z: 960,  yyyymmddhhmmss:1656049171018},
       {longitude: 119.13663554484476, latitude: 45.963013907042956, z: 960, yyyymmddhhmmss:1656049271018},
       {longitude: 119.13613329953036, latitude: 45.96357079427627, z: 960,  yyyymmddhhmmss:1656049371018}]


   let moveData=tableData
    var date = new Date(dateStringToTimestamp(moveData[0].yyyymmddhhmmss));
    var start = Cesium.JulianDate.fromDate(date); //获取第一个点的时间
    console.log('start',date)
    viewer.clock.startTime = start;  //将多个点的第一个点设为轨迹播放的开始时间
    viewer.clock.currentTime = start; //修改时间轴的当前时间
    viewer.clock.shouldAnimate = true; //开始播放
    var property = new Cesium.SampledPositionProperty();
    for (var z = 0; z < moveData.length; z++) {
        var item = moveData[z];
        var thisTime = Cesium.JulianDate.fromDate(new Date(dateStringToTimestamp(item.yyyymmddhhmmss)));
        var position = Cesium.Cartesian3.fromDegrees(item.longitude, item.latitude);

        // 添加每一个链接点的信息，到达的时间以及坐标位置
        property.addSample(thisTime, position);
    }
    //设置贴地
    property.setInterpolationOptions({
        interpolationDegree: 2,
        interpolationAlgorithm: Cesium.LagrangePolynomialApproximation
    });
    var times = property._property._times;
    var startTime = times[0].clone();
    var stopTime = times[times.length - 1].clone();
    var entitydd = viewer.entities.add({
        availability: new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({
            start: startTime,
            stop: stopTime
        })]),
        id:'xjLine',
        position: property, // 点集
        billboard:{
            image:imageUrl,
            scale:0.3,
            pixelOffset:new Cesium.Cartesian3(0,0),
            verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
            // horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
            heightReference : Cesium.HeightReference.CLAMP_TO_GROUND, // 高度参考为贴地
            clampToGround:true  //是否贴地
        },
        label:{
            text : txtName,
            font : '16px sans-serif',
            fillColor : Cesium.Color.WHITE,
            outlineColor : Cesium.Color.BLACK,
            outlineWidth : 1,
            style : Cesium.LabelStyle.FILL_AND_OUTLINE,
            disableDepthTestDistance: Number.POSITIVE_INFINITY,
            verticalOrigin: Cesium.VerticalOrigin.TOP,
            heightReference : Cesium.HeightReference.CLAMP_TO_GROUND, // 高度参考为贴地
            clampToGround:true,  //是否贴地
            pixelOffset: new Cesium.Cartesian2(-60, -80)//此属性为设置偏移量
        },
    });

    console.log('property',property)
    // viewer.flyTo(entitydd)
    // viewer.flyTo({
    //     destination : Cesium.Cartesian3.fromDegrees(tableData[0].longitude, tableData[0].latitude, 200),
    // });
    viewer.camera.flyTo({
        destination : Cesium.Cartesian3.fromDegrees(moveData[0].longitude, moveData[0].latitude, 5000),
    });
    var property2=[]
    for (var z = 0; z < moveData.length; z++) {
        var item = moveData[z];
        property2.push( Cesium.Cartesian3.fromDegrees(item.longitude, item.latitude));
    }
    var linePath=viewer.entities.add({
        polyline: {
            positions: property2,
            width: 15,
            material: new Cesium.PolylineArrowMaterialProperty(Cesium.Color.YELLOW),
            heightReference : Cesium.HeightReference.CLAMP_TO_GROUND, // 高度参考为贴地
            clampToGround:true  //是否贴地
        },
        id:'linedata'
    });
// 将线条提升到指定高度
    linePath.polyline.height = 1000;
// 添加文本标签
    var label = viewer.entities.add({
        position : entitydd.position,
        label : {
            text : txtName,
            font : '16px sans-serif',
            fillColor : Cesium.Color.WHITE,
            outlineColor : Cesium.Color.BLACK,
            outlineWidth : 1,
            //show:false,
            style : Cesium.LabelStyle.FILL_AND_OUTLINE,
            disableDepthTestDistance: Number.POSITIVE_INFINITY,
            verticalOrigin : Cesium.VerticalOrigin.TOP,
            pixelOffset : new Cesium.Cartesian2(90, -80),
            heightReference : Cesium.HeightReference.CLAMP_TO_GROUND, // 高度参考为贴地
            clampToGround:true  //是否贴地
        },
        id:'labelID'

    });

// 每帧更新文本标签的位置
    viewer.scene.postRender.addEventListener(function() {
        var position = entitydd.position.getValue(viewer.clock.currentTime);
        label.position = position;
        var datalist=new Date((viewer.clock.currentTime).toString())
        var dateString = datalist.toLocaleString();
        label.label.text=dateString;
        //console.log('entitydd',dateString)
    });

}
function removeXjLine(){
    viewer.entities.removeById('xjLine');
    viewer.entities.removeById('linedata');
    viewer.entities.removeById('labelID');
}
// function clearDivContent(divId) {
//     // 获取目标 div 元素
//     const div = document.getElementById(divId);
//
//     // 将元素内容设置为空字符串
//     div.innerHTML = '';
//     // div.style.display='none';
// }
var currentDate = new Date();
var currentDateStr = currentDate.toLocaleDateString();
var carArray = [
    {lon: 119.08773736122919,lat: 45.89828619130883,name:"辽A80001",typeName:"车辆",deptName:"-",date:currentDateStr,dataType:"0"},
    {lon: 119.09498159385788,lat: 45.89992076650627,name:"辽A80002",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.10327038095083,lat: 45.90208716962376,name:"辽A80003",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.10941848165649,lat: 45.90953679058304,name:"辽A80004",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.10573984051999,lat: 45.90820311594975,name:"辽A80005",typeName:"车辆",deptName:"-",date:currentDateStr,dataType:"0"},
    {lon: 119.10570418473164,lat: 45.90895509034784,name:"辽A80006",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.10274101159408,lat: 45.906791617755275,name:"辽A80007",typeName:"车辆",deptName:"-",date:currentDateStr,dataType:"0"},
    {lon: 119.08551467472282,lat: 45.91303775099692,name:"辽A80008",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.08366023211619,lat: 45.91203522669397,name:"辽A80009",typeName:"车辆",deptName:"-",date:currentDateStr,dataType:"0"},
    {lon: 119.09324923689522,lat: 45.9199371081196,name:"辽A80010",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.09105095115811,lat: 45.91673759128135,name:"辽A80011",typeName:"车辆",deptName:"-",date:currentDateStr,dataType:"0"},
    {lon: 119.09659222767488,lat: 45.92594494720799,name:"辽A80012",typeName:"车辆",deptName:"-",date:currentDateStr,dataType:"0"},
    {lon: 119.09711962317486,lat: 45.920498734560134,name:"辽A80013",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.09880019052923,lat: 45.9186661137141,name:"辽A80014",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.1191958477817,lat: 45.90915808396862,name:"辽A80015",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.11399750372279,lat: 45.90831204480646,name:"辽A80016",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.11129066263067,lat: 45.90804944737346,name:"辽A80017",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.12460453481715,lat: 45.912017180713256,name:"辽A80018",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.12864721228267,lat: 45.91201270378103,name:"辽A80019",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.13434125671672,lat: 45.91241921561609,name:"辽A80020",typeName:"车辆",deptName:"-",date:currentDateStr,dataType:"0"},
    {lon: 119.14585587918464,lat: 45.92467118286677,name:"辽A80021",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.14506344975497,lat: 45.92606120407288,name:"辽A80022",typeName:"车辆",deptName:"-",date:currentDateStr,dataType:"0"},
    {lon: 119.14111579231528,lat: 45.926515380190665,name:"辽A80023",typeName:"车辆",deptName:"-",date:currentDateStr,dataType:"0"},
    {lon: 119.13755163327131,lat: 45.926394292148984,name:"辽A80024",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.1287070622879,lat: 45.93401492749536,name:"辽A80025",typeName:"车辆",deptName:"-",date:currentDateStr,dataType:"0"},
    {lon: 119.12898825945953,lat: 45.93607823228354,name:"辽A80026",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.12131445942397,lat: 45.93639192668996,name:"辽A80027",typeName:"车辆",deptName:"-",date:currentDateStr,dataType:"0"},
    {lon: 119.11971242341646,lat: 45.93680859132171,name:"辽A80028",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.11608713525776,lat: 45.93973754675962,name:"辽A80029",typeName:"车辆",deptName:"-",date:currentDateStr,dataType:"0"},
    {lon: 119.1177914814015,lat: 45.940905629199385,name:"辽A80030",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.11864809628065,lat: 45.94335894527604,name:"辽A80031",typeName:"车辆",deptName:"-",date:currentDateStr,dataType:"0"},
    {lon: 119.12557933404523,lat: 45.94209601646083,name:"辽A80032",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.13584291806629,lat: 45.95550577692545,name:"辽A80033",typeName:"车辆",deptName:"-",date:currentDateStr,dataType:"0"},
    {lon: 119.1480627920452,lat: 45.96157793576302,name:"辽A80034",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.15261251082265,lat: 45.96118024283475,name:"辽A80035",typeName:"车辆",deptName:"-",date:currentDateStr,dataType:"0"},
    {lon: 119.15961035391976,lat: 45.95800001218108,name:"辽A80036",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.16048348918923,lat: 45.95494917912944,name:"辽A80037",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.16119576603128,lat: 45.9485358040979,name:"辽A80038",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.1609323903502,lat: 45.94414707898738,name:"辽A80039",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
    {lon: 119.16083645722618,lat: 45.9426201684231,name:"辽A80040",typeName:"车辆",deptName:"-",date:"",dataType:"1"},
];

var peopleArry=[
    {lon: 119.07717862748943,lat: 45.90357399571154,name:"BH0001",typeName:"人员",deptName:"行政部",date:currentDateStr,dataType:"0"},
    {lon: 119.07930958128073,lat: 45.90038396298686,name:"BH0002",typeName:"人员",deptName:"行政部",date:"",dataType:"1"},
    {lon: 119.08775046502166,lat: 45.898989114678635,name:"BH0003",typeName:"人员",deptName:"行政部",date:"",dataType:"1"},
    {lon: 119.09795904034304,lat: 45.900880064207655,name:"BH0004",typeName:"人员",deptName:"行政部",date:"",dataType:"1"},
    {lon: 119.10604345455502,lat: 45.9025124624536,name:"BH0005",typeName:"人员",deptName:"行政部",date:"",dataType:"1"},
    {lon: 119.10765516805382,lat: 45.90819477107015,name:"BH0006",typeName:"人员",deptName:"技术部",date:"",dataType:"1"},
    {lon: 119.10371088524458,lat: 45.9098891782188,name:"BH0007",typeName:"人员",deptName:"技术部",date:currentDateStr,dataType:"0"},
    {lon: 119.09341508870597,lat: 45.91513080580828,name:"BH0008",typeName:"人员",deptName:"技术部",date:"",dataType:"1"},
    {lon: 119.09689335509297,lat: 45.91742118254626,name:"BH0009",typeName:"人员",deptName:"技术部",date:"",dataType:"1"},
    {lon: 119.09690612981396,lat: 45.920900027938856,name:"BH0010",typeName:"人员",deptName:"开采部",date:currentDateStr,dataType:"0"},
    {lon: 119.1122238655364, lat: 45.90629938961518,name:"BH0011",typeName:"人员",deptName:"开采部",date:"",dataType:"1"},
    {lon: 119.1237138323953, lat: 45.90701757072016,name:"BH0012",typeName:"人员",deptName:"开采部",date:currentDateStr,dataType:"0"},
    {lon: 119.13577678292486,lat: 45.90800206846531,name:"BH0013",typeName:"人员",deptName:"开采部",date:"",dataType:"1"},
    {lon: 119.14527770941473,lat: 45.908151474540716,name:"BH0014",typeName:"人员",deptName:"开采部",date:"",dataType:"1"},
    {lon: 119.09907055878845,lat: 45.92484998297486,name:"BH0015",typeName:"人员",deptName:"开采部",date:currentDateStr,dataType:"0"},
    {lon: 119.11163238216412,lat: 45.935247540217446,name:"BH0016",typeName:"人员",deptName:"开采部",date:"",dataType:"1"},
    {lon: 119.08920148723023,lat: 45.9276853528244,name:"BH0017",typeName:"人员",deptName:"开采部",date:"",dataType:"1"},
    {lon: 119.08420784592779,lat: 45.91612534013872,name:"BH0018",typeName:"人员",deptName:"开采部",date:"",dataType:"1"},
    {lon: 119.12325052149613,lat: 45.93499307220748,name:"BH0019",typeName:"人员",deptName:"开采部",date:currentDateStr,dataType:"0"},
    {lon: 119.1205611763373, lat: 45.93169587964321,name:"BH0020",typeName:"人员",deptName:"加工部",date:currentDateStr,dataType:"0"},
    {lon: 119.12847692460551,lat: 45.92866346881088,name:"BH0021",typeName:"人员",deptName:"加工部",date:"",dataType:"1"},
    {lon: 119.1334704740718, lat: 45.926406759555356,name:"BH0022",typeName:"人员",deptName:"加工部",date:currentDateStr,dataType:"0"},
    {lon: 119.13598213759457,lat: 45.925737682406,name:"BH0023",typeName:"人员",deptName:"加工部",date:"",dataType:"1"},
    {lon: 119.1270996167732, lat: 45.91606841732225,name:"BH0024",typeName:"人员",deptName:"加工部",date:"",dataType:"1"},
    {lon: 119.13357859514338,lat: 45.94526355737914,name:"BH0025",typeName:"人员",deptName:"加工部",date:currentDateStr,dataType:"0"},
    {lon: 119.15271274076518,lat: 45.95266510876959,name:"BH0026",typeName:"人员",deptName:"加工部",date:"",dataType:"1"},
    {lon: 119.1608184052162, lat: 45.94610475839148,name:"BH0027",typeName:"人员",deptName:"加工部",date:"",dataType:"1"},
    {lon: 119.16070391452209,lat: 45.93467856980931,name:"BH0028",typeName:"人员",deptName:"后勤保障部",date:"",dataType:"1"},
    {lon: 119.1594898388025, lat: 45.92917845391373,name:"BH0029",typeName:"人员",deptName:"后勤保障部",date:currentDateStr,dataType:"0"},
    {lon: 119.15717377287577,lat: 45.92918091582172,name:"BH0030",typeName:"人员",deptName:"后勤保障部",date:"",dataType:"1"},
    {lon: 119.14983119562089,lat: 45.92685809436568,name:"BH0031",typeName:"人员",deptName:"后勤保障部",date:currentDateStr,dataType:"0"},
    {lon: 119.14797079372931,lat: 45.92943478530266,name:"BH0032",typeName:"人员",deptName:"后勤保障部",date:"",dataType:"1"},
    {lon: 119.14459218786556,lat: 45.91907759494789,name:"BH0033",typeName:"人员",deptName:"后勤保障部",date:"",dataType:"1"},
    {lon: 119.133029763345,  lat:45.95336618967969,name:"BH0034",typeName:"人员",deptName:"后勤保障部",date:currentDateStr,dataType:"0"},
    {lon: 119.13385137475922,lat: 45.95168805374196,name:"BH0035",typeName:"人员",deptName:"后勤保障部",date:"",dataType:"1"},
    {lon: 119.12683432121564,lat:45.9545248052779,name:"BH0036",typeName:"人员",deptName:"后勤保障部",date:"",dataType:"1"},
]
carArray.forEach(function(item) {
    var sevenDaysAgoDate = new Date(currentDate.getTime() - Math.random() * 7 * 24 * 60 * 60 * 1000);
    if (item.date===''){
        item.date = sevenDaysAgoDate.toLocaleDateString();
    }
});
peopleArry.forEach(function(item) {
    var sevenDaysAgoDate = new Date(currentDate.getTime() - Math.random() * 7 * 24 * 60 * 60 * 1000);
    if (item.date===''){
        item.date = sevenDaysAgoDate.toLocaleDateString();
    }
});
/**
 * 添加图标方法
 */
function addMarker(mkType,dataList){
    //添加点击事件
    var handler_person_car = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);//viewer.scene.
    handler_person_car.setInputAction(function(
        click) {
        $("#moxing").hide();
        // let cartesian = viewer.camera.pickEllipsoid(click.position);
        // let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
        // let lng = Cesium.Math.toDegrees(cartographic.longitude); // 经度
        // let lat = Cesium.Math.toDegrees(cartographic.latitude); // 纬度
        var pick = viewer.scene.pick(click.position);
        if (pick.primitive.id !=null) {//pick || pick.id == "Entity"
            console.log(pick.id.dataInfo)
            var positionData=pick.id.dataInfo.position;
            // $(".top_right_table").show();
            Cflyto(positionData.longitude,positionData.latitude,5000);
            // viewer.flyTo(pick.id);
            //添加信息到详情数据div中
            // document.getElementById('DetailedInformation_text_psCar').style.display='block';
            addContentToDiv('DetailedInformation_text_psCar',$('#typeSelect').val()==='1'?"车辆"+'定位':"人员"+'定位',pick.id.dataInfo.esection,pick.id.dataInfo.ename,pick.id.dataInfo.eaddtime,'查看轨迹','查看摄像头')
        }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    if (mkType==='0'){
        dataList.forEach(function (item) {
            addMarkerByPerson(item,"./images/人员定位.png",35,55,60,'icon_ps')
        });
    }
    if (mkType==='1'){
        dataList.forEach(function (item) {
            addMarkerByPerson(item,"./images/车辆定位.png",35,60,70,'icon_car')
        });
    }
}
var dateRangeAll=''
var deptMsg=''
function generateLicensePlate() {
    var provinceCode = '辽';
    var cityCode = 'A';
    var areaCode = String.fromCharCode(Math.floor(Math.random() * 6) + 65); // 生成随机的 A~F 字母
    var numberCode = Math.floor(Math.random() * 10000).toString().padStart(4, '0'); // 生成随机的 4 位数字
    return provinceCode + cityCode + areaCode + numberCode;
}
function randomDateTimeInRange(dateRangeStr) {
    if (dateRangeAll!==''){
        // 将起始时间和结束时间从字符串中分离出来
        var dateRange = dateRangeStr.split('~');
        var startDate = dateRange[0];
        var endDate = dateRange[1];
        // 生成随机日期时间
        var startDateObj = new Date(startDate);
        var endDateObj = new Date(endDate);
        var randomTime = startDateObj.getTime() + Math.random() * (endDateObj.getTime() - startDateObj.getTime());
        var randomDate = new Date(randomTime);
        // 返回随机日期时间的字符串表示形式
        // console.log(randomDate.toLocaleString())
        return randomDate.toLocaleDateString();
    }else{
        return  new Date().toLocaleDateString()
    }

}
var tableIns;
var table;
layui.use(['dropdown', 'util', 'layer', 'table','form','laydate','slider'], function() {
    var form = layui.form;
    var dropdown = layui.dropdown
        , layer = layui.layer
     table = layui.table;
    var $=layui.jquery;
    var laydate = layui.laydate;
    // 渲染搜索下拉框
    form.render('select');
    // 监听定位类型下拉框的选择事件
    form.on('select(typeSelect)', function(data) {
        if (data.value==='0'){
            var select = $('#searchSelect');
            // 移除禁用属性
            select.removeAttr('disabled');
            // 设置选中项为空
            select.val('');
            form.render('select');
            console.log('人')
            // (status,'zy')
        }
        if (data.value==='1'){
            // 获取下拉框
            var select = $('#searchSelect');
            // 添加禁用属性
            select.attr('disabled', 'disabled');
            // 设置选中项为空
            select.val('');
            form.render('select');
        }

    });
    form.on('select(typeDateSelect)', function(data) {
        // console.log('你选择的是：', data.value, data.elem);
        // split(false,'zy')
        // if (data.value==='0'){
        //     // console.log('实时')
        //     var timerange = $('#timerange');
        //     // 添加禁用属性
        //     timerange.attr('disabled', 'disabled');
        //     timerange.val('');
        //     // (status,'zy')
        // }
        // if (data.value==='1'){
        //     var timerange = $('#timerange');
        //     // 移除禁用属性
        //     timerange.removeAttr('disabled');
        //     timerange.val('');
        // }

    });
    form.on('select(quizz)', function(data) {
        if (data.value!==''){
            console.log($('#quizy').val())
            if (data.value===$('#quizy').val()){
                layer.msg('左右两侧数据不能相同！');
                $('#quizz').val('')
                layui.form.render('select');
            }
        }
    });
    form.on('select(quizy)', function(data) {
        if (data.value!==''){
            console.log($('#quizz').val())
            if (data.value===$('#quizz').val()){
                layer.msg('左右两侧数据不能相同！');
                $('#quizy').val('')
                layui.form.render('select');
            }
        }
    });
    //渲染时间
    //日期时间范围
    laydate.render({
        elem: '#timerange'
        ,type: 'date'
        ,theme: '#006A8E'
        ,range: '~'
    });
    // 创建表格


    // 清除表格
    window.clearTabel = function() {
        $('#myTable').hide();
        if (tableIns) {
            tableIns.reload({data: []});
            tableIns = null;
        }
    }
    //滑动条调整透明度
    var slider = layui.slider;
    slider.render({
        elem: '#slideSelect'
        , value: 100 //初始值
        , min: 0
        , max: 100
        , step: 10 //步长
        , input: true, //输入框
        // , setTips: function (value) { //自定义提示文本
        //     return value + 'GB';
        // },
        theme: '#1E9FFF' //主题色
        , change: function (val) {
            var selectElement = $(".custom-select");
            var selectedIndex = selectElement.prop("selectedIndex");
            var selectedValue = selectElement.val();
            console.log(selectedValue);
            if (selectedValue=="底图透明度"){
                console.log(val)
                // 再设置baseColor
                viewer.imageryLayers._layers.forEach(layer => {
                    layer.alpha = val/100; // 我们可以设置为0
                });
                viewer.scene.globe.baseColor = Cesium.Color.TRANSPARENT;
                viewer.scene.globe.showGroundAtmosphere = false;
                // viewer.scene.globe.baseColor = new Cesium.Color(0, 0, 0, 0);
                viewer.scene.globe.translucency.enabled = true;
                viewer.scene.globe.undergroundColor = undefined;
                if (val===100){
                    viewer.imageryLayers._layers.forEach(layer => {
                        layer.alpha = 1; // 我们可以设置为0
                    });
                    // 地球球体透明
                    viewer.scene.globe.showGroundAtmosphere = true;
                    viewer.scene.globe.baseColor = new Cesium.Color(1, 1, 1, 1);
                    // viewer.scene.globe.baseColor = new Cesium.Color(0, 0, 0, 0);
                    viewer.scene.globe.translucency.enabled = flase;
                    // viewer.scene.globe.undergroundColor = undefined;
                }
            }else if (selectedValue=="遥感影像"){
                console.log("遥感影像")
            }else {
                console.log("三维模型")
                window.tilesets_QX_Group.forEach((item, index) => {
                    item.style = new Cesium.Cesium3DTileStyle({
                        color: `color('rgba(255,255,255,${val/100})')`,
                    });
                })
                window.tilesets_DWG_Group.forEach((item, index) => {
                    item.style = new Cesium.Cesium3DTileStyle({
                        color: `color('rgba(255,255,255,${val/100})')`,
                    });
                })
            }

        }
    })
    })
//添加人员图标
/**
 *
 * @param location
 * @param markTypeUrl
 * @param markHeight
 * @param iconSize2D
 * @param width
 * @param height
 */
let markIdNum = 1
let psMarkerIdList = []
function addMarkerByPerson(location, markTypeUrl, markHeight, width, height,icon_type) {
    let enetity = {}
    enetity = viewer.entities.add({
        id: location.ename,
        dataInfo:location,
        _type: icon_type,
        position: Cesium.Cartesian3.fromDegrees(location.position.longitude, location.position.latitude, markHeight), //经纬度与高度
        billboard: {
            image: markTypeUrl,
            width: width,
            height: height,
            horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
            verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
            scale: 0.5,
            heightReference:Cesium.HeightReference.CLAMP_TO_GROUND,
            clampToGround:true , //是否贴地

            //heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
            disableDepthTestDistance: Number.POSITIVE_INFINITY,
            // sizeInMeters: true, //随比例缩放开启
        },
        label : {
            text : location.ename,
            font : '16px sans-serif',
            fillColor : Cesium.Color.WHITE,
            outlineColor : Cesium.Color.BLACK,
            outlineWidth : 1,
            style : Cesium.LabelStyle.FILL_AND_OUTLINE,
            verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
            pixelOffset : new Cesium.Cartesian2(0, -50),
            heightReference:Cesium.HeightReference.CLAMP_TO_GROUND,
            clampToGround:true , //是否贴地
            //heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
            disableDepthTestDistance: Number.POSITIVE_INFINITY,
        },
    })
    psMarkerIdList.push(enetity.id)
    markIdNum++;
}

/**
 * 清除人员车辆定位图标
 */
function removeMarkers(){
    // clearTabel()
    removeXjLine()
    // document.getElementById('DetailedInformation_text_psCar').style.display='none';
    // clearDivContent('DetailedInformation_text_psCar')
    try{
        //三维实体移除
        psMarkerIdList.forEach(c => {
            viewer.entities.removeById(c);
            // viewer.entities.remove(viewer.entities.getById(c))
        })
    }catch (e) {

    }
}
var historyId=''
let HistoryData={};
function getDataMarkers(){
    console.log('搜索')
    //判空
    if ($('#typeSelect').val()===''){
        layer.msg('请选择定位类型！');
        return
    }
    if ($('#typeDateSelect').val()===''){
        layer.msg('请选择数据类型！');
        return
    }
    // if ($('#typeDateSelect').val()==='1'&&$('#timerange').val()===''){
    //     layer.msg('请选择历史时间范围！');
    //     return
    // }
    // if ($('#typeSelect').val()==='0'&&$('#searchSelect').val()===''){
    //     layer.msg('请选择人员部门！');
    //     return
    // }
    var dataList=[]
    var allResult=[]
    var dataType=$('#typeSelect').val()
    var requirParameter={
        //id
        id:'',
        //姓名
        ename:'',
        //岗位名称
        epost:'',
        //部门名称
        esection:'',
        //用户状态
        estatus:'',
        //照片URL
        ephotourl:'',
        //手机号码
        ephone:'',
        //手机唯一标志
        edevice:'',
        //电子邮箱
        eemail:'',
        //创建时间
        eaddtime:'',
    }
    requirParameter.esection=$('#searchSelect').val();
    var dataList=getData(requirParameter);
    // console.log(requirParameter)
    // if ($('#typeSelect').val()==='0'){
    //     dataList=peopleArry
    //     if ($('#typeDateSelect').val()==='0'){//实时数据
    //         var result = dataList.filter(function(item) {
    //             return item.dataType === "0";
    //         });
    //         //选择部门信息
    //         var result2 = result.filter(function(item) {
    //             if ($('#searchSelect').val()==="全部部门"){
    //                 return item;
    //             }else{
    //                 return item.deptName === $('#searchSelect').val();
    //             }
    //         });
    //         allResult=result2
    //     }else{ //历史数据
    //         var result = dataList.filter(function(item) {
    //             return item.dataType === "1";
    //         });
    //         //选择部门信息
    //         var result2 = result.filter(function(item) {
    //             if ($('#searchSelect').val()==="全部部门"){
    //                 return item;
    //             }else{
    //                 return item.deptName === $('#searchSelect').val();
    //             }
    //         });
    //         // console.log('resule2',result2)
    //         //选择时间范围
    //         // let result3 = result2.filter(item => {
    //         //     var dateRangeStr=$('#timerange').val();
    //         //     var dateRange = dateRangeStr.split('~');
    //         //     let startDate = new Date(dateRange[0]);
    //         //     let endDate = new Date(dateRange[1]);
    //         //     let itemDate = new Date(item.date);
    //         //     // console.log('itemDate',itemDate)
    //         //     return itemDate >= startDate && itemDate <= endDate;
    //         // });
    //         allResult=result2
    //     }
    // }else{
    //     dataList=carArray
    //     if ($('#typeDateSelect').val()==='0'){//实时数据
    //         var result = dataList.filter(function(item) {
    //             return item.dataType === "0";
    //         });
    //         allResult=result
    //     }else{
    //         var result = dataList.filter(function(item) {
    //             return item.dataType === "1";
    //         });
    //         //选择时间范围
    //         // let result3 = result.filter(item => {
    //         //     var dateRangeStr=$('#timerange').val();
    //         //     var dateRange = dateRangeStr.split('~');
    //         //     let startDate = new Date(dateRange[0]);
    //         //     let endDate = new Date(dateRange[1]);
    //         //     let itemDate = new Date(item.date);
    //         //     return itemDate >= startDate && itemDate <= endDate;
    //         // });
    //         allResult=result
    //     }
    // }
    // //筛选用户检索条件
    // var result3 = allResult.filter(function(item) {
    //     return item.name.includes($('#searchTitle').val());
    // });
    removeMarkers()
    //添加图标
    // addMarker(dataType,dataList)
    //查询数据


}
function addTable(dataList){
    $('#myTable').show();
    var tableData=dataList
    var tableCols=[]
    if($('#typeSelect').val()==='0'){
        //人员定位
        tableCols = [
            {field: 'ename', title: '姓名',width:60},
            {field: 'esection', title: '部门',width:73},
            {field: 'id', title: '编号',width:85},
            // {field: 'date', title: '时间',width:100},
            {toolbar: "#tool", title: '操作',width:166, align: "center",templet:"#tool",}
        ];
    }else if($('#typeSelect').val()==='1'){
        //车辆定位
        tableCols = [
            {field: 'vehicleId', title: '车牌号',width:100},
            {field: 'esection', title: '部门',width:73},
            {field: 'eid', title: '编号',width:85},
            // {field: 'date', title: '时间',width:100},
            {toolbar: "#tool", title: '操作',width:166, align: "center",templet:"#tool",}
        ];
    }

    tableIns = table.render({
        elem: '#myTable',
        // cellMinWidth: 40,
        // cellMaxWidth: 60,
        cols: [tableCols],
        data: tableData,
        // height:390,
        page: {
            theme:"#0D2644",
            layout:[ 'page', 'next','count','skip']}
        // ,groups: 1 //只显示 1 个连续页码
        // ,skin: 'line' //行边框风格
        // ,even: true //开启隔行背景
        ,size: 'sm' //小尺寸的表格
        ,limit: 8, // 每页显示10行数据
    });
    //表头工具
    table.on('tool(myTable)', function(obj){
        var data = obj.data;
        console.log(data)
        switch(obj.event){
            case 'showLine':
                console.log(data)
                //实时数据查看摄像头
                if (data.typeName==="人员"){
                    $("#vidoplay").show();
                    console.log('打开')
                    let video = document.getElementById('vidoplayid');
                    if (Hls.isSupported()) {
                        // video.display='block';
                        var hls = new Hls();
                        hls.loadSource('https://hls01open.ys7.com/openlive/e06f942409784b0b89efb5d464697455.m3u8');
                        hls.attachMedia(video);
                        hls.on(Hls.Events.MANIFEST_PARSED, function () {
                        });
                    }
                    video.play();
                }else{
                    console.log(data)
                    $("#vidoplay").show();
                    let video = document.getElementById('vidoplayid');
                    if (Hls.isSupported()) {
                        // video.display='block';
                        var hls = new Hls();
                        hls.loadSource('https://hls01open.ys7.com/openlive/e06f942409784b0b89efb5d464697455.m3u8');
                        hls.attachMedia(video);
                        hls.on(Hls.Events.MANIFEST_PARSED, function () {
                        });
                    }
                    video.play();
                }
                // var btn=$(this).find("[lay-event='showLine']")
                // if (btn.prevObject[0].innerText==="查看轨迹"){
                //     btn.prevObject[0].innerText="关闭轨迹"
                //     addlinePlay(data.typeName,data.name)
                // }else{
                //     btn.prevObject[0].innerText="查看轨迹"
                //     removeXjLine()
                // }
                break;
            case 'searchHistory':
                //展开右侧界面
                console.log("我是历史数据"+data)
                document.getElementById('historyItem').style.display='block';
                HistoryData=data;
                historyId=data.name

                break;
        };
    });
    //监听行单击事件（双击事件为：rowDouble）
    table.on('row(myTable)', function(obj){
        var positionData = obj.data.position;
        var data = obj.data;
        console.log(obj)
        console.log(data)
        var entity = viewer.entities.getById(data.ename);
        Cflyto(positionData.longitude,positionData.latitude,5000);
        // viewer.flyTo(entity);
        console.log(data)
        // document.getElementById('DetailedInformation_text_psCar').style.display='block';
        addContentToDiv('DetailedInformation_text_psCar',$('#typeSelect').val()==='1'?"车辆"+'定位':"人员"+'定位',data.esection,data.ename,data.eaddtime,'查看轨迹','查看摄像头')
    });
    function tool(data){
        console.log(data)
        if (data.dataType==='0'){
            return "<a class='layui-btn layui-btn-xs' lay-event='showLine' >查看摄像头</a>"
        }else {
            return "<a class='layui-btn layui-btn-xs' lay-event='searchHistory' >查看历史定位</a>"
        }
    }
}
function Cflyto(longitude, latitude, height, heading = 0, pitch = -90, roll = 0) {
    viewer.camera.flyTo({
        destination: Cesium.Cartesian3.fromDegrees(longitude, latitude, height),
        orientation: {
            heading: Cesium.Math.toRadians(heading),
            pitch: Cesium.Math.toRadians(pitch),
            roll: roll
        }
    });
}
var history_data=[];
function getHistoryData(requirParameter){
    var dataList= [];
    var dataType='0';
    // var url='http://127.0.0.1:8282/kuangqu/tposition/findistoryListByCondition';
    var url='http://3510b38g11.zicp.fun:13894/kuangqu/tposition/findistoryListByCondition';
    $.ajax({
        type: 'POST',
        headers: {
            Authorization:localTokenData
        },
        data: JSON.stringify(requirParameter),
        // url: 'http://192.168.0.108:8282/kuangqu/sys/user/login',  //后台地址注意要改
        // url: 'http://3510b38g11.zicp.fun:13894/kuangqu/sys/user/login',  //后台地址注意要改
        url:url,
        contentType: "application/json",
        success: function (res) {

            dataList=res.data;
            // addTable(dataList)
            removeMarkers()
            historyTable(dataList)
            history_data=dataList;
            // //添加图标
            // addMarker(dataType,dataList)
        }
    })
    // console.log(dataList)
    // return dataList;
}
function showhistoryLine(){
        var typename='',name='';
        if($('#typeSelect').val()==='0'){
            typename='人员'
        }else{
            typename='车辆'
        }

    if(history_data.length==0){
        layer.msg('请先查询历史数据');

    }else{
        addlinePlay(typename,history_data[0].id,history_data)
    }

}
function getData(requirParameter){
    var dataList= [];
    var dataType=$('#typeSelect').val();
    var url='';
    if($('#typeSelect').val()==='0'){
        //人员定位
        url='http://3510b38g11.zicp.fun:13894/kuangqu/temployee/listByCondition'
        // url='http://127.0.0.1:8282/kuangqu/temployee/listByCondition'
    }else if($('#typeSelect').val()==='1'){
        //车辆定位
        // url='http://127.0.0.1:8282/kuangqu/vehicleInfo/listByCondition'
        url='http://3510b38g11.zicp.fun:13894/kuangqu/vehicleInfo/listByCondition'
    }
    $.ajax({
        type: 'POST',
        headers: {
            Authorization:localTokenData
        },
        data: JSON.stringify(requirParameter),
        // url: 'http://192.168.0.108:8282/kuangqu/sys/user/login',  //后台地址注意要改
        // url: 'http://3510b38g11.zicp.fun:13894/kuangqu/sys/user/login',  //后台地址注意要改
        url:url,
        contentType: "application/json",
        success: function (res) {
            dataList=res.data;
            addTable(dataList)
            // removeMarkers()
            //添加图标

            addMarker(dataType,dataList)
        }
    })
    // console.log(dataList)
    // return dataList;
}
//按钮关闭
function closeVideo() {
    let video = document.getElementById('vidoplayid');
    video.pause();
    $("#vidoplay").hide();
}
function gethistoryMarkers(){
    removeXjLine()
    $('#historyTable').show();
    //根据时间范围和id查询数据
    if ($('#timerange').val()===''){
        layer.msg('请选择历史时间范围！');
        return
    }
    HistoryData.datarange=$('#timerange').val();
    getHistoryData(HistoryData);

    // var dataList=[]
    // if ($('#typeSelect').val()==='0') {
    //     dataList = peopleArry
    // }else{
    //     dataList = carArray
    // }
    // console.log('dataList',dataList)
    // var result = dataList.filter(function(item) {
    //     console.log(item.dataType)
    //     return item.dataType === "1";
    // });
    // console.log('result',result)
    // var result3 = result.filter(item => {
    //     var dateRangeStr=$('#timerange').val();
    //     var dateRange = dateRangeStr.split('~');
    //     let startDate = new Date(dateRange[0]);
    //     let endDate = new Date(dateRange[1]);
    //     let itemDate = new Date(item.date);
    //     return itemDate >= startDate && itemDate <= endDate;
    // });
    // console.log('result3',result3)
    // //筛选用户检索条件
    // var tableData = result3.filter(function(item) {
    //     return item.name.includes(historyId);
    // });
    //选择时间范围

    // var tableCols = [
    //     // {field: 'typeName', title: '类型',width:60},
    //     {field: 'deptName', title: '部门',width:73},
    //     {field: 'name', title: '编号',width:85},
    //     {field: 'date', title: '时间',width:100},
    //     {toolbar: "#toolHis", title: '操作',width:157, align: "center"}
    // ];
    // tableIns = table.render({
    //     elem: '#historyTable',
    //     // cellMinWidth: 40,
    //     // cellMaxWidth: 60,
    //     cols: [tableCols],
    //     data: tableData,
    //     // height:390,
    //     page: {
    //         theme:"#0D2644",
    //         layout:[ 'page', 'next','count','skip']}
    //     // ,groups: 1 //只显示 1 个连续页码
    //     // ,skin: 'line' //行边框风格
    //     // ,even: true //开启隔行背景
    //     ,size: 'sm' //小尺寸的表格
    //     ,limit: 8, // 每页显示10行数据
    // });
    // //表头工具
    // table.on('tool(historyTable)', function(obj) {
    //     var data = obj.data;
    //     console.log(data)
    //     switch (obj.event) {
    //         case 'showHisLine':
    //             var btn=$(this).find("[lay-event='showHisLine']")
    //             if (btn.prevObject[0].innerText==="查看轨迹"){
    //                 btn.prevObject[0].innerText="关闭轨迹"
    //                 addlinePlay(data.typeName,data.name)
    //             }else{
    //                 btn.prevObject[0].innerText="查看轨迹"
    //                 removeXjLine()
    //             }
    //             break;
    //     }
    // })
}
function historyTable(tableData){
    var tableCols = [
        {field: 'yyyymmdd', title: '日期',width:168},
        {field: 'longitude', title: '经度',width:140},
        {field: 'latitude', title: '纬度',width:140},
        // {field: 'date', title: '时间',width:100},
        // {toolbar: "#toolHis", title: '操作',width:130, align: "center"}
    ];
    var HtableIns = table.render({
        elem: '#historyTable',
        // cellMinWidth: 40,
        // cellMaxWidth: 60,
        cols: [tableCols],
        toolbar: '#viewTrack',
        data: tableData,
        // height:390,
        page: {
            theme:"#0D2644",
            layout:[ 'page', 'next','count','skip']}
        // ,groups: 1 //只显示 1 个连续页码
        // ,skin: 'line' //行边框风格
        // ,even: true //开启隔行背景
        ,size: 'sm' //小尺寸的表格
        ,limit: 8, // 每页显示10行数据
    });
    //表头工具
    // table.on('toolbar(historyTable)', function(obj) {
    //     var data = obj.data;
    //     var typename='',name='';
    //     if($('#typeSelect').val()==='0'){
    //         typename='人员'
    //     }else{
    //         typename='车辆'
    //     }
    //     console.log(data)
    //     switch (obj.event) {
    //         case 'showHisLine1':
    //             var btn=$(this).find("[lay-event='showHisLine1']")
    //             if (btn.prevObject[0].innerText==="查看轨迹"){
    //                 btn.prevObject[0].innerText="关闭轨迹"
    //                 console.log("asdf:"+"tableData.id:"+tableData.id+"tableData:"+tableData)
    //                 addlinePlay(typename,tableData[0].id,tableData)
    //             }else{
    //                 btn.prevObject[0].innerText="查看轨迹"
    //                 removeXjLine()
    //             }
    //             break;
    //     }
    // })
}


function closeHistory(){
    history_data=[];
    //关闭轨迹
    removeXjLine()
    $('#timerange').val('');
    //关闭历史搜索栏
    document.getElementById('historyItem').style.display='none';
    // $('#historyTable').innerText = '';
    table.render({
        elem: '#historyTable'
    })
    $('#historyTable').hide();
}
function Sxcx_flyto(e){
    CloseEntities1();
    var name=$(e).attr("name");
    var json = eval(data1);
    json.forEach((item, index) => {
        console.log(item,index)
        if (item.name == name) {
            var lon= item.lon;
            var lat= item.lat;
            var id= item.id;
            var url= item.url;

            viewer.camera.flyTo({
                destination: Cesium.Cartesian3.fromDegrees(lon, lat, 11500),
                orientation: {
                    heading:Cesium.Math.toRadians(0),
                    pitch:Cesium.Math.toRadians(60),
                    roll:0,
                }
            });
            idstr[0]=id;
            AddIcon(lat,lon,id,url)
            sxname.innerHTML="名字："+item.name+"1号";
            sxaddress.innerHTML="地址："+item.address;
            sxlon.innerHTML="经度："+lon;
            sxlat.innerHTML="纬度："+lat;
        $("#sxxx").show();
            $("#sxxxsc").click(function (){
                $("#sxxx").hide();
            })
        }else{
            console.log("s")
        }
    })


}
